package main.java.design.simplefactory;

/**
 * <p>
 *     工厂角色
 * </p>
 *
 * @author : wangdejian
 * @version 1.0
 * @date : 2020/6/9 21:11
 */
public class Factory {

    public Shape getShape(String shapeType) {

        if (shapeType.equalsIgnoreCase("circle")) {
            return new Circle();
        } else if (shapeType.equalsIgnoreCase("square")) {
            return new Square();
        }
        return null;
    }


    /**
     * 反射
     *
     * @param cla
     * @return
     */
    public Shape getShape(Class cla) {
        Shape iShape = null;

        try {
            iShape = (Shape)cla.asSubclass(Shape.class).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return iShape;
    }
}
